import Vue from 'vue'
import Message from './Message.vue'

const PopupBox = Vue.extend(Message)
let flag = true
Message.install = function (data) {
  const instance = new PopupBox({ data }).$mount()

  if (flag) {
    document.body.appendChild(instance.$el)
    flag = false
  }

  Vue.nextTick(() => {
    instance.show = true
    // show 和弹窗组件里的show对应，用于控制显隐
  })
  window.setTimeout(() => {
    if (document.body.contains(instance.$el)) {
      document.body.removeChild(instance.$el)
    }
    flag = true
  }, 1500)
}

export default Message